<template>
	<view>
		<view class="bz p-5">
			<view class="py-3 titlex">
				绑定手机号
			</view>
			<view style="height: 100rpx;"></view>
			<view class="cu-form-group px-0" style="border-bottom: 1px solid #eee;">
				<input placeholder="请输入手机号" type="number" maxlength="11" v-model="phone" placeholder-style="font-size:27rpx;letter-spacing: 3rpx;"></input>
			</view>
			<!-- <view class="cu-form-group px-0" style="border-bottom: 1px solid #eee;">
				<input placeholder="请输入验证码" type="number" v-model="code" placeholder-style="font-size:27rpx;letter-spacing: 3rpx;"></input>
				<button class='cu-btn code' v-if="sendStatus" @tap="sendCode">发送验证码</button>
				<button class='cu-btn code' v-else>{{num}}s</button>
			</view> -->
			
			
			<view style="height: 150rpx;"></view>
			<view class="bz p-1">
				<button class="cu-btn bg-red margin-tb-sm lg" style="width: 100%;background: #007BEF;" @tap="register">绑定</button>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				radio:false,
				r2:true,
				phone:'',
				password:'',
				saft_code:'',
				u_code:'',
				status:false,
				sendStatus:true,
				num:60,
				code:'',
			}
		},
		onShow() {
			console.log('bindPhone');
		},
		onNavigationBarButtonTap(e){
			if(e.float=='right'){
				uni.navigateTo({
					url:"../regter/regter"
				})
			}
			
		},
		methods: {
			RadioChange(e) {
				this.radio = !this.radio
			},
			goTo(){
				uni.navigateTo({
					url:"../xieyi/xieyi"
				})
			},
			sendCode(){
				if(this.phone < 1){uni.showToast({title:'请输入手机号', icon:"none"}); return ;}
				this.sendStatus=false;
				this.sendNum();
				let _this=this;
				uni.showLoading({
				    title: '发送中...'
				});
				this.$http({
					url: '/login/sendcodeOne',
					method: 'post',
					data: {
						phone:_this.phone
					}
				}).then((res) => {
					uni.hideLoading();
					console.log(res);
					if (res.code == '0') {
						uni.setStorageSync('user', res.data);
						uni.setStorageSync('level',res.data.level)
						uni.showToast({
						    title: res.data,
						    duration: 1000,
							icon:'none'
						});	
						setTimeout(function(){
							uni.switchTab({
								url:"../index/index"
							})
						})
					}else{
						uni.showToast({
						    title: res.data,
						    duration: 1000,
							icon:'none'
						});	
					}
				}).catch((err) => {
					uni.hideLoading();
					console.log(err)
				
				})
				
			},
			sendNum(){
				
				let _this=this;
				let time=setInterval(function(){
					if(_this.num==1){
						_this.num=60;
						_this.sendStatus=true;
					}else{
						_this.num--;
						
					}
				},1000)
			},
			register(){
			
				var _this=this;
				if(this.phone < 1){uni.showToast({title:'请输入手机号', icon:"none"}); return ;}
				uni.showLoading({
				    title: '提交中...'
				});
				var arr={
					phone:_this.phone,
					openId:uni.getStorageSync('user').openId,
					weChatName:uni.getStorageSync('user').name
				};
				arr=JSON.stringify(arr);
				this.$http({
					url: '/IWeiXinService.bindInfo',
					method: 'post',
					data: arr
				}).then((res) => {
					uni.hideLoading();
					if (res.code == '0') {
						let user = uni.getStorageSync('user');
						user.customer=res.data
						uni.setStorageSync('user', user);
						uni.showToast({
						    title: res.data,
						    duration: 1000,
							icon:'none'
						});	
						setTimeout(function(){
							uni.switchTab({
								url:"../appointment/index"
							})
						},1000)
					}else{
						uni.showToast({
						    title: res.data,
						    duration: 1000,
							icon:'none'
						});	
					}
				}).catch((err) => {
					uni.hideLoading();
					console.log(err)
				
				})
				
			}
		}
	}
</script>

<style>
page{
	background: #fff;
	height: 100%;
}
.titlex{
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 600;
	color: #444;
	line-height: 36px;
	letter-spacing: 5rpx;
	font-weight: bold;
}
.input{
	font-size: 27rpx;
	letter-spacing: 3rpx;
}
.forget{
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #333333;
}
.footer{
	position: fixed;
	bottom: 40rpx;
	font-size: 23rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	text-align: center;
}
.tl{
	color: #007BEF;
}
.code{
	font-size: 23rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #007BEF;
	padding: 10rpx 20rpx;
	height: 46rpx;
	line-height: 46rpx;
}
</style>
